﻿

using System;
using Sharp.Platform.Other;

namespace Sharp.Platform
{
    /// <summary>
    /// 实体
    /// </summary>
    [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
    public class DataHandlerAttribute : System.Attribute
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="DataHandlerAttribute"/> class.
        /// </summary>
        public DataHandlerAttribute()
        {
            this.Mode = "Details";
            this.Title = "浏览";
            this.OrderId = 0;
            this.HasWindow = true;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="DataHandlerAttribute"/> class.
        /// </summary>
        /// <param name="mode">The mode.</param>
        /// <param name="title">标题</param>
        /// <param name="orderId">The order identifier.</param>
        public DataHandlerAttribute(string mode, string title, int orderId)
        {
            this.Mode = mode;
            this.Title = title;
            this.OrderId = orderId;
        }

        public DataHandlerAttribute(string mode, string title, int orderId, string onClientClick)
            : this(mode, title, orderId)
        {
            OnClientClick = onClientClick;
        }

        /// <summary>
        /// Gets or sets the mode.
        /// </summary>
        /// <value>The mode.</value>
        public string Mode { get; set; }

        /// <summary>
        /// 标题
        /// </summary>
        /// <value>标题</value>
        public string Title { get; set; }

        /// <summary>
        /// Gets or sets the order identifier.
        /// </summary>
        /// <value>The order identifier.</value>
        public int OrderId { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether this instance has window.
        /// </summary>
        /// <value><c>null</c> if [has window] contains no value, <c>true</c> if [has window]; otherwise, <c>false</c>.</value>
        public bool? HasWindow { get; set; }

        /// <summary>
        /// Gets or sets the width.
        /// </summary>
        /// <value>The width.</value>
        public int Width { get; set; }

        /// <summary>
        /// Gets or sets the height.
        /// </summary>
        /// <value>The height.</value>
        public int Height { get; set; }

        /// <summary>
        /// Gets or sets the URL.
        /// </summary>
        /// <value>The URL.</value>
        public string Url { get; set; }


        /// <summary>
        /// Iframe Style
        /// 0：以iframe打开链接；1：以窗体打开链接；2：url的资源是否当作js来执行
        /// </summary>
        /// <value>The is i frame style.</value>
        public int IsIFrameStyle { get; set; }

        /// <summary>
        /// 客户端 Ajax 函数
        /// </summary>
        /// <value>The ajax function.</value>
        public string AjaxFunction { get; set; }

        public string OnClientClick { get; set; }

        /// <summary>
        /// Gets the handler.
        /// </summary>
        /// <returns>DataHandlerInfo.</returns>
        public ToolButtonInfo GetHandler()
        {
            ToolButtonInfo info = new ToolButtonInfo()
            {
                Model = this.Mode,
                Title = this.Title,
                //HasWindow = !this.HasWindow.HasValue || this.HasWindow.Value,
                Height = this.Height,
                Width = this.Width,
                Url = this.Url,
                IsIFrameStyle = this.IsIFrameStyle,
                AjaxFunction = this.AjaxFunction,
                OnClientClick = this.OnClientClick
            };
            return info;
        }
    }
}